home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games Extra 1996 September / Amiga Games Extra CD-ROM 9-1996.iso / userbox / publicdomain / vim-4.2 / src / mkcmdtab.c < prev    next >
C/C++ Source or Header  |  1996-06-09  |  2KB  |  114 lines

  1. /* vi:set ts=4 sw=4:
  2.  *
  3.  * VIM - Vi IMproved        by Bram Moolenaar
  4.  *
  5.  * Do ":help uganda"  in Vim to read copying and usage conditions.
  6.  * Do ":help credits" in Vim to see a list of people who contributed.
  7.  */
  8.  
  9. /*
  10.  * mkcmdtab.c: separate program that reads cmdtab.tab and produces cmdtab.h
  11.  *
  12.  *    call with: mkcmdtab cmdtab.tab cmdtab.h
  13.  */
  14.  
  15. #include "vim.h"
  16.  
  17. #if defined(UTS4)
  18.     int
  19. #else
  20.     void
  21. #endif
  22. main(argc, argv)
  23.     int        argc;
  24.     char    **argv;
  25. {
  26.     register int    c;
  27.     char            buffer[100];
  28.     int                count;
  29.     int                i;
  30.     FILE            *ifp, *ofp;
  31.  
  32.     if (argc != 3)
  33.     {
  34.         fprintf(stderr, "Usage: mkcmdtab cmdtab.tab cmdtab.h\n");
  35.         exit(10);
  36.     }
  37.     ifp = fopen(argv[1], "r");
  38.     if (ifp == NULL)
  39.     {
  40.         perror(argv[1]);
  41.         exit(10);
  42.     }
  43.     ofp = fopen(argv[2], "w");
  44.     if (ofp == NULL)
  45.     {
  46.         perror(argv[2]);
  47.         exit(10);
  48.     }
  49.  
  50.     while ((c = getc(ifp)) != '|' && c != EOF)
  51.         putc(c, ofp);
  52.     fprintf(ofp, "THIS FILE IS AUTOMATICALLY PRODUCED - DO NOT EDIT");
  53.     while ((c = getc(ifp)) != '|' && c != EOF)
  54.         ;
  55.     while ((c = getc(ifp)) != '|' && c != EOF)
  56.         putc(c, ofp);
  57.  
  58.     count = 0;
  59.     while ((c = getc(ifp)) != '|' && c != EOF)
  60.     {
  61.         putc(c, ofp);
  62.         while ((c = getc(ifp)) != '"' && c != EOF)
  63.             putc(c, ofp);
  64.         putc(c, ofp);
  65.  
  66.         i = 0;
  67.         while ((c = getc(ifp)) != '"' && c != EOF)
  68.         {
  69.             putc(c, ofp);
  70.             buffer[i++] = c;
  71.         }
  72.         putc(c, ofp);
  73.         buffer[i] = 0;
  74.  
  75.         while ((c = getc(ifp)) != '\n' && c != EOF)
  76.             putc(c, ofp);
  77.         putc(c, ofp);
  78.  
  79.         switch (buffer[0])
  80.         {
  81.             case '@':    strcpy(buffer, "at");
  82.                         break;
  83.             case '!':    strcpy(buffer, "bang");
  84.                         break;
  85.             case '<':    strcpy(buffer, "lshift");
  86.                         break;
  87.             case '>':    strcpy(buffer, "rshift");
  88.                         break;
  89.             case '=':    strcpy(buffer, "equal");
  90.                         break;
  91.             case '&':    strcpy(buffer, "and");
  92.                         break;
  93.             case '~':    strcpy(buffer, "tilde");
  94.                         break;
  95.             case '#':    strcpy(buffer, "pound");
  96.                         break;
  97.         }
  98.                     
  99.         fprintf(ofp, "#define CMD_%s %d\n", buffer, count++);
  100.     }
  101.  
  102.     fprintf(ofp, "#define CMD_SIZE %d\n", count);
  103.  
  104.     while ((c = getc(ifp)) != '|' && c != EOF)
  105.         putc(c, ofp);
  106.  
  107.     if (c != '|')
  108.     {
  109.         fprintf(stderr, "not enough |'s\n");
  110.         exit(1);
  111.     }
  112.     exit(0);
  113. }
  114.